//
//  SinglePhoneNumberView.m
//  RentingCar
//
//  Created by wmwMAC on 17/4/7.
//  Copyright © 2017年 Cassie. All rights reserved.
//

#import "SinglePhoneNumberView.h"



@interface SinglePhoneNumberView ()<UITextFieldDelegate>

@property (nonatomic, strong) UITextField *textF;

@end

@implementation SinglePhoneNumberView


-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self addTextFieldUI];
    }
    return self;
}


-(void)addTextFieldUI{
    
    CGFloat SecuritybtnWidth = 0;
    
    _textF = [[UITextField alloc]initWithFrame:CGRectMake(kSize*3, 0, kUIScreenWidth-6*kSize - SecuritybtnWidth, CGRectGetHeight(self.frame))];
    _textF.placeholder = @"请输入您的手机号";
    _textF.delegate = self;
    _textF.font = kfont(14);
    [_textF setAutocorrectionType:UITextAutocorrectionTypeNo];//关闭首字母大写
    [_textF setAutocapitalizationType:UITextAutocapitalizationTypeNone];//关闭联想
    UIButton *button = [_textF valueForKey:@"_clearButton"];
    [button setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    _textF.clearButtonMode = UITextFieldViewModeWhileEditing;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChange:) name:UITextFieldTextDidChangeNotification object:_textF];
//    _textF.borderStyle = UITextBorderStyleLine;//设置输入框边框样式
    _textF.layer.borderColor = [RGBColor(248, 248, 248) CGColor];
    _textF.layer.borderWidth = 1.0;
    //留出空隙
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 30)];
//    UIImageView *imaview = [[UIImageView alloc] initWithFrame:CGRectMake(5, 7, 13, 15)];
//    imaview.image = [UIImage imageNamed:@""];
//    [view addSubview:imaview];
    _textF.leftView = view;
    _textF.leftViewMode = UITextFieldViewModeAlways;//设置leftview显示的时机
    [self addSubview:_textF];
    
    
    //黑色线
//    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(kSize*3, CGRectGetMaxY(_textF.frame), kUIScreenWidth-6*kSize, 1)];
//    lineView.backgroundColor = RGBColor(248, 248, 248);
//    [self addSubview:lineView];
}


#pragma mark  -----------------  输入框内容改变 调用block传值   ---------------
- (void)textChange:(NSNotification *)noti{
    
    
    if (noti.object == _textF) {
        // 执行代理方法
        
    }
    
    if (self.returnPhoneBlock != nil) {
        self.returnPhoneBlock(_textF.text);
    }
}
-(void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

-(void)returnPhone:(ReturnPhoneBlock)block{
    self.returnPhoneBlock = block;
}


@end
